package org.com.cis.cf.measure;


public class IDCGScorer extends MetricScorer{
	
	public double score(int five_s, int four_s, int three_s, int two_s, int one_s, boolean k_flag)
	{
		double score = 0.0;
		
		if ( !k_flag ) {
			
			score = 
				five_s * (31/Math.log(2)) 
				+ four_s * (15/Math.log(2+five_s)) 
				+ three_s * (7/Math.log(2+five_s+four_s))
				+ two_s * (3/Math.log(2+five_s+four_s+three_s)) 
				+ one_s * (1/Math.log(2+five_s+four_s+three_s+two_s));
		} else {
			int num[] = {five_s, four_s, three_s, two_s, one_s};
			
			int cumulation = 0, i = 0, position = 1, rate = 0;
			while ( cumulation < k) {
				rate = 5-i;
				score += num[i] * (Math.pow(2, rate)-1) / (Math.log(1+position));
				position += num[i];
				cumulation += num[i];
				++i;
			}
			if( cumulation>k ) {
				position -= num[--i];
				score -= (cumulation-k) * (Math.pow(2, rate)-1) / (Math.log(1+position));
			}
		}
		
		return score;
	}
}
